# == Schema Information
#
# Table name: base_departments
#
#  id          :integer          not null, primary key
#  name        :string(255)
#  name_cn     :string(255)
#  parent_id   :integer
#  customer_id :integer
#  created_at  :datetime         not null
#  updated_at  :datetime         not null
#

class Base::Department < ApplicationRecord

  scope :roots, -> {where(parent_id: nil)}
  scope :this, -> { where(customer_id: Customer.current&.id) }

  has_many :children, :class_name => 'Base::Department', :foreign_key => 'parent_id'

  def to_s
    name
  end
end
